<template>
  <div class="home-container">
    <el-container>
      <el-header class="header">
        <div class="header-content">
          <h1 class="logo">旅游路线规划系统</h1>
          <div class="user-info">
            <el-dropdown @command="handleCommand">
              <span class="user-dropdown">
                <el-icon><User /></el-icon>
                欢迎，{{ username }}
                <el-icon><ArrowDown /></el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item command="logout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </div>
      </el-header>
      
      <el-container>
        <el-aside width="200px" class="sidebar">
          <el-menu
            :default-active="activeMenu"
            class="sidebar-menu"
            @select="handleMenuSelect"
          >
            <el-menu-item index="/home">
              <el-icon><House /></el-icon>
              <span>首页</span>
            </el-menu-item>
            <el-menu-item index="/route-generator">
              <el-icon><Location /></el-icon>
              <span>路线生成</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        
        <el-main class="main-content">
          <div class="welcome-section">
            <el-card shadow="hover">
              <template #header>
                <div class="welcome-header">
                  <h2>欢迎使用旅游路线规划系统</h2>
                </div>
              </template>
              <div class="text-red"></div>
              <div class="welcome-content">
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-card shadow="hover" class="feature-card">
                      <div class="feature-icon">
                        <el-icon size="48" color="#409EFF"><Location /></el-icon>
                      </div>
                      <h3>智能路线规划</h3>
                      <p>基于AI技术，为您生成个性化的旅游路线，考虑景点分布、时间安排等因素。</p>
                    </el-card>
                  </el-col>
                  <el-col :span="8">
                    <el-card shadow="hover" class="feature-card">
                      <div class="feature-icon">
                        <el-icon size="48" color="#67C23A"><Check /></el-icon>
                      </div>
                      <h3>路线验证</h3>
                      <p>使用百度地图API验证路线的合理性，确保行程安排科学可行。</p>
                    </el-card>
                  </el-col>
                  
                  <el-col :span="8">
                    <el-card shadow="hover" class="feature-card">
                      <div class="feature-icon">
                        <el-icon size="48" color="#E6A23C"><Star /></el-icon>
                      </div>
                      <h3>个性化定制</h3>
                      <p>根据您的预算、出行天数、人数等需求，定制专属的旅游方案。</p>
                    </el-card>
                  </el-col>
                </el-row>
                
                <div class="action-section">
                  <el-button
                    type="primary"
                    size="large"
                    @click="$router.push('/route-generator')"
                  >
                    开始规划路线
                  </el-button>
                </div>
              </div>
            </el-card>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { User, ArrowDown, House, Location, Check, Star } from '@element-plus/icons-vue'

const router = useRouter()
const route = useRoute()

const username = ref('用户')

const activeMenu = computed(() => route.path)

const handleMenuSelect = (index: string) => {
  router.push(index)
}

const handleCommand = async (command: string) => {
  if (command === 'logout') {
    try {
      await ElMessageBox.confirm('确定要退出登录吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
      
      localStorage.removeItem('token')
      ElMessage.success('已退出登录')
      router.push('/login')
    } catch {
      // 用户取消
    }
  }
}
</script>

<style scoped>
.home-container {
  height: 100vh;
}

.header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 0 20px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

.logo {
  margin: 0;
  font-size: 24px;
  font-weight: bold;
}

.user-dropdown {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: white;
}

.sidebar {
  background-color: #f5f7fa;
  border-right: 1px solid #e4e7ed;
}

.sidebar-menu {
  border-right: none;
}

.main-content {
  padding: 20px;
  background-color: #f5f7fa;
}

.welcome-section {
  max-width: 1200px;
  margin: 0 auto;
}

.welcome-header h2 {
  margin: 0;
  color: #303133;
  text-align: center;
}

.welcome-content {
  padding: 20px 0;
}

.feature-card {
  text-align: center;
  height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.feature-icon {
  margin-bottom: 16px;
}

.feature-card h3 {
  margin: 0 0 12px 0;
  color: #303133;
  font-size: 18px;
}

.feature-card p {
  margin: 0;
  color: #606266;
  line-height: 1.6;
}

.action-section {
  text-align: center;
  margin-top: 40px;
}
</style> 